﻿using System;
using System.Collections.Generic;
using RpcHelper;
using RpcModel;
using SqlExecHelper;
using Wedonek.RpcStore.Service.Model;

namespace Wedonek.RpcStore.Service.DAL
{
        internal class RpcMerDAL : SqlExecHelper.SqlBasicClass
        {
                public RpcMerDAL() : base("RpcMer")
                {

                }
                public void SetMer(long id, RpcMerSetParam param)
                {
                        if(!base.Update(param, "Id", id))
                        {
                                throw new ErrorException ("rpc.mer.set.error");
                        }
                }
                public long AddMer(RpcMerDatum add)
                {
                        base.Insert(add, out long id);
                        return id;
                }
                public RpcMer GetMer (long id)
                {
                        return base.GetRow<long, RpcMer> ("Id", id);
                }
                public void DropMer(long id)
                {
                        if(!base.Drop("Id", id))
                        {
                                throw new ErrorException ("rpc.mer.drop.error");
                        }
                }
                public RpcMer[] Query (string name, IBasicPage paging, out long count)
                {
                        List<ISqlWhere> wheres = new List<ISqlWhere>();
                        if (!name.IsNull())
                        {
                                wheres.Add(new LikeSqlWhere("SystemName", 50) { Value = name });
                        }
                        return base.Query<RpcMer> ("Id", paging.Index, paging.Size, out count, wheres.ToArray());
                }

                internal BasicRpcMer[] GetBasic (long[] ids)
                {
                        return base.Get<long, BasicRpcMer> ("Id", ids);
                }
        }
}
